Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
Why Nuxt making multiple request for the "user" endpoint?

There is an Express server and a Nuxt client. Nuxt version is 2.15.7.

Entire auth configuration:

// nuxt.config.js
auth: {
  plugins: [
    {
      src: '~/plugins/axios',
      ssr: true
    },
    {
      src: '~/plugins/auth'
    }
  ],
  cookie: {
    prefix: 'auth.',
    options: {
      path: '/',
      secure: process.env.NODE_ENV === 'production' ? true : false
    }
  },
  localStorage: {
    prefix: 'auth.'
  },
  vuex: {
    namespace: 'auth'
  },
  strategies: {
    local: {
      scheme: 'refresh',
      token: {
        property: 'accessToken',
        maxAge: 900,
        global: true,
        name: 'Authorization',
        type: 'Bearer'
      },
      refreshToken: {
        property: 'refreshToken',
        data: 'refreshToken',
        maxAge: 5184000
      },
      user: {
        property: 'user',
        autoFetch: false
      },
      endpoints: {
        login: {
          url: '/user/sign_in',
          method: 'post'
        },
        logout: {
          url: '/user/sign_out',
          method: 'delete'
        },
        refresh: {
          url: '/user/refresh',
          method: 'get'
        },
        user: {
          url: '/user/profile',
          method: 'get'
        }
      }
    }
  },
  redirect: {
    login: '/auth/sign_in',
    logout: '/',
    callback: '/auth/sign_in',
    home: '/'
  }
}

When I refresh the page in the browser, I see this in the browser log:

enter image description here

This message comes from here:

// plugins/axios.ts
import { AxiosRequestConfig } from 'axios'

export default function ({ $axios, }: any) {
  $axios.onRequest((config: AxiosRequestConfig) => {
    console.log('Making request to ' + config.url)
  })
}

There are also two requests in the server logs. But in the first request I can get, for example, cookies, and in the second one comes this:

// console.log(req.cookies)

[Object: null prototype] {}

Can you please tell me why there are two requests?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem was caused by the back end returning this after sign in:

{
  "is": 1
}

And should return this:

{
  "user": {
    "is": 1
  }
}

😬

After I added the "user" object, nuxt auth accepted the information and started working correctly.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda